package cn.lh.controller;

import cn.lh.config.Resp;
import cn.lh.event.MyEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @描述:
 * @版权: Copyright (c) 2022
 * @作者: linhong
 * @版本: 1.0.0
 * @创建时间: 2023/6/26
 */
@Api(tags = "测试")
@RestController
@RequestMapping("/test")
public class TestController extends BaseController{

    @Value("${upload.file.path}")
    private String uploadFilePath;

    @Value("${server.port}")
    private String port;

    @Resource
    private ApplicationContext applicationContext;

    @ApiOperation("Event测试")
    @GetMapping("/event")
    public void testEvent(@RequestParam Integer code, @RequestParam  String message){
        System.err.println("准备发送事件");
        MyEvent myEvent = new MyEvent(this, message, code);
        applicationContext.publishEvent(myEvent);
        System.err.println("事件发送完毕");
    }

    @ApiOperation("测试ng负载均衡,获取服务端口")
    @GetMapping("/getPort")
    public Resp<String> getPort(){
        return ok(port);
    }

}
